source = {"a": {"b": 1, "c": 2}, "d": {"e": 3, "f": {"g": 4}}}


def flatmap(src, target=None, prefix=""):
    if target == None:
        target = {}
    for k, v in src.items():
        if isinstance(v, (list, tuple, set, dict)):
            flatmap(v, target, prefix=prefix+k+".")
        else:
            target[prefix+k] = v
    return target

if __name__ == "__main__":

    print(flatmap(source))
